//
//  ZhuTuFIrstCell.m
//  JinChengYun
//
//  Created by 金橙云 on 2017/5/2.
//  Copyright © 2017年 金橙云. All rights reserved.
//
#define WIDTH_W [UIScreen mainScreen].bounds.size.width
#import "ZhuTuFIrstCell.h"

@implementation ZhuTuFIrstCell

-(instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self)
    {
        _yuanLab = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, WIDTH_W, 30)];
        _yuanLab.backgroundColor = [UIColor orangeColor];
        _yuanLab.textColor = [UIColor whiteColor];
        _yuanLab.text = @"   主售房源案场业绩(万元)";
        _yuanLab.font = [UIFont systemFontOfSize:14];
        [self addSubview:_yuanLab];
        //分段控件
        //_segmented = [[UISegmentedControl alloc] initWithItems:@[@"日",@"周",@"月",@"季",@"年"]];
          _segmented = [[UISegmentedControl alloc] initWithItems:@[@"月",@"季",@"年"]];
        _segmented.frame = CGRectMake(10, 40, WIDTH_W-10*2, 20);
        _segmented.selectedSegmentIndex = 0;//设置默认选择项索引
        _segmented.tintColor = [UIColor orangeColor];
        [_segmented addTarget:self action:@selector(segmentedBtnClick:) forControlEvents:UIControlEventValueChanged];
        [self addSubview:_segmented];

        self.barChart = [[ZFBarChart alloc] initWithFrame:CGRectMake(-40, CGRectGetMaxY(_segmented.frame), SCREEN_WIDTH+40, 265)];
        self.barChart.dataSource = self;
        self.barChart.delegate = self;
       // self.barChart.valueTextColor = [UIColor redColor];
        self.barChart.isResetAxisLineMaxValue = YES;
        self.barChart.axisLineValueColor = [UIColor whiteColor];
        [self addSubview:self.barChart];
        [self.barChart strokePath];

        _segMentIndex=0;
    }
    return self;
}
/**
 _zhuMoneyAnalayseArr = @[@[zhudayCountArr,zhudayNameArr,zhujiDuMax],@[zhuzhouCountArr,zhuzhouNameArr,zhuZhouMax],@[zhumonthCountArr,zhunianNameArr,zhuMonthMax],@[zhujiduCountArr,zhujiduNameArr,zhujiDuMax],@[zhunianCountArr,zhunianNameArr,zhuNianMax]];

 */
#pragma mark - ZFGenericChartDataSource

- (NSArray *)valueArrayInGenericChart:(ZFGenericChart *)chart{
    return self.dataArr[_segMentIndex][0];
   
    
}

//设置柱状图的宽度
- (CGFloat)barWidthInBarChart:(ZFBarChart *)barChart
{
    return 30;
}
- (NSArray *)nameArrayInGenericChart:(ZFGenericChart *)chart{
    return self.dataArr[_segMentIndex][1];
  
    
}

- (NSArray *)colorArrayInGenericChart:(ZFGenericChart *)chart{
    return @[ZFLvColor];
}
/**
 *  每组里面，bar与bar之间的间距(若不设置，默认为5.f)(当只有一组数组时，此方法无效)
 */

- (CGFloat)paddingForGroupsInBarChart:(ZFBarChart *)barChart{
    return 50;
}

- (CGFloat)axisLineMaxValueInGenericChart:(ZFGenericChart *)chart{//最大值
    
    NSString *str = self.dataArr[_segMentIndex][2];
    return str.floatValue;
   // return 500;
}

- (NSUInteger)axisLineSectionCountInGenericChart:(ZFGenericChart *)chart{
    return 10;
}
- (NSArray *)gradientColorArrayInBarChart:(ZFBarChart *)barChart{
    ZFGradientAttribute * gradientAttribute1 = [[ZFGradientAttribute alloc] init];
    gradientAttribute1.colors = @[(id)ZFColor(15, 212, 201, 1).CGColor, (id)ZFWhite.CGColor];
    gradientAttribute1.locations = @[@(0.5), @(0.99)];
    gradientAttribute1.startPoint = CGPointMake(0, 0.5);
    gradientAttribute1.endPoint = CGPointMake(1, 0.5);
    
    return [NSArray arrayWithObjects:gradientAttribute1, nil];
}

-(void)segmentedBtnClick:(UISegmentedControl *)sender
{
    NSLog(@"测试");
    _segMentIndex = sender.selectedSegmentIndex;
    [self.barChart strokePath];
    
}



- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
